package at.htlkaindorf.jee.jasper.jasperreportsexample1;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.LinkedList;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;

/**
 *
 * @author Thomas
 */
public class Test {

    private static final String report1Path = "jasper/report1.jasper";

    public static void main(String[] args) throws JRException, IOException {
        InputStream report1TemplateFile = ClassLoader.getSystemClassLoader().getResourceAsStream(report1Path);
        if (report1TemplateFile == null) {
            throw new IllegalArgumentException("could not find report template");
        }

        HashMap<String, Object> parameter = new HashMap<>();
        LinkedList<TestBean> data = new LinkedList<>();
        data.add(new TestBean("kartoffel"));
        JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(data);
        
        JasperPrint report = JasperFillManager.fillReport(report1TemplateFile, parameter, dataSource);
        JasperExportManager.exportReportToPdfFile(report, "report1.pdf");
    }

    public static class TestBean {

        private String value;

        public TestBean() {
        }

        public TestBean(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }

        public void setValue(String value) {
            this.value = value;
        }
    }
}
